// Source : http://www.tsinsen.com/A1064
// Author : Modnar
// Date   : 2019-03-31

#include <iostream>

const int MAX_SIZE = 120;
const int MAX_DATA_NUM = 5;

// Use Perm(0, n, lst) to generate the full-arrangement sequence.
// Here, the lst is the array [1, 2, 3, ..., n]
void Perm(int start, int end, int lst[]) {
    if (start == end) {
        for (int i = 0; i < end; ++i)
            std::cout << lst[i] << " ";
        std::cout << std::endl;
    }
    for (int i = start; i < end; ++i) {
        std::swap(lst[start], lst[i]);
        Perm(start+1, end, lst);
        std::swap(lst[start], lst[i]);
    }
}

int seq[MAX_SIZE][MAX_DATA_NUM] = {
                {1,2,3,4,5}, {1,2,3,5,4}, {1,2,4,3,5}, {1,2,4,5,3},
                {1,2,5,3,4}, {1,2,5,4,3}, {1,3,2,4,5}, {1,3,2,5,4},
                {1,3,4,2,5}, {1,3,4,5,2}, {1,3,5,2,4}, {1,3,5,4,2},
                {1,4,2,3,5}, {1,4,2,5,3}, {1,4,3,2,5}, {1,4,3,5,2},
                {1,4,5,2,3}, {1,4,5,3,2}, {1,5,2,3,4}, {1,5,2,4,3},
                {1,5,3,2,4}, {1,5,3,4,2}, {1,5,4,2,3}, {1,5,4,3,2},
                {2,1,3,4,5}, {2,1,3,5,4}, {2,1,4,3,5}, {2,1,4,5,3},
                {2,1,5,3,4}, {2,1,5,4,3}, {2,3,1,4,5}, {2,3,1,5,4},
                {2,3,4,1,5}, {2,3,4,5,1}, {2,3,5,1,4}, {2,3,5,4,1},
                {2,4,1,3,5}, {2,4,1,5,3}, {2,4,3,1,5}, {2,4,3,5,1},
                {2,4,5,1,3}, {2,4,5,3,1}, {2,5,1,3,4}, {2,5,1,4,3},
                {2,5,3,1,4}, {2,5,3,4,1}, {2,5,4,1,3}, {2,5,4,3,1},
                {3,1,2,4,5}, {3,1,2,5,4}, {3,1,4,2,5}, {3,1,4,5,2},
                {3,1,5,2,4}, {3,1,5,4,2}, {3,2,1,4,5}, {3,2,1,5,4},
                {3,2,4,1,5}, {3,2,4,5,1}, {3,2,5,1,4}, {3,2,5,4,1},
                {3,4,1,2,5}, {3,4,1,5,2}, {3,4,2,1,5}, {3,4,2,5,1},
                {3,4,5,1,2}, {3,4,5,2,1}, {3,5,1,2,4}, {3,5,1,4,2},
                {3,5,2,1,4}, {3,5,2,4,1}, {3,5,4,1,2}, {3,5,4,2,1},
                {4,1,2,3,5}, {4,1,2,5,3}, {4,1,3,2,5}, {4,1,3,5,2},
                {4,1,5,2,3}, {4,1,5,3,2}, {4,2,1,3,5}, {4,2,1,5,3},
                {4,2,3,1,5}, {4,2,3,5,1}, {4,2,5,1,3}, {4,2,5,3,1},
                {4,3,1,2,5}, {4,3,1,5,2}, {4,3,2,1,5}, {4,3,2,5,1},
                {4,3,5,1,2}, {4,3,5,2,1}, {4,5,1,2,3}, {4,5,1,3,2},
                {4,5,2,1,3}, {4,5,2,3,1}, {4,5,3,1,2}, {4,5,3,2,1},
                {5,1,2,3,4}, {5,1,2,4,3}, {5,1,3,2,4}, {5,1,3,4,2},
                {5,1,4,2,3}, {5,1,4,3,2}, {5,2,1,3,4}, {5,2,1,4,3},
                {5,2,3,1,4}, {5,2,3,4,1}, {5,2,4,1,3}, {5,2,4,3,1},
                {5,3,1,2,4}, {5,3,1,4,2}, {5,3,2,1,4}, {5,3,2,4,1},
                {5,3,4,1,2}, {5,3,4,2,1}, {5,4,1,2,3}, {5,4,1,3,2},
                {5,4,2,1,3}, {5,4,2,3,1}, {5,4,3,1,2}, {5,4,3,2,1}};

int main(int argc, char *argv[]) {
    bool find_ans = false;
    int i;
    for (i = 0; i < MAX_SIZE; ++i) {
        find_ans = true;
        if (seq[i][4] == 2 || seq[i][4] == 3) 
            continue;
        if (seq[i][0] == 1 || seq[i][0] == 2) {
            if (seq[i][4] != 1) 
                continue;
        } else { 
            if (seq[i][4] == 1) 
                continue;
        }
        if (seq[i][1] == 1 || seq[i][1] == 2) {
            if (seq[i][1] != 2) 
                continue;
        } else {
            if (seq[i][1] == 2) 
                continue;
        }
        if (seq[i][2] == 1 || seq[i][2] == 2) {
            if (seq[i][0] != 5) 
                continue;
        } else {
            if (seq[i][0] == 5) 
                continue;
        }
        if (seq[i][3] == 1 || seq[i][3] == 2) {
            if (seq[i][2] == 1) 
                continue;
        } else {
            if (seq[i][2] != 1) 
                continue;
        }
        if (seq[i][4] == 1 || seq[i][4] == 2) {
            if (seq[i][3] != 1) 
                continue;
        } else {
            if (seq[i][3] == 1) 
                continue;
        }
        if (find_ans)
            break;
    }
    for (int j = 0; j < MAX_DATA_NUM; ++j)
        std::cout << seq[i][j] << " ";
    std::cout << std::endl;
    return 0;
}
